package com.baozun.houji.order.activity

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.View
import com.baozhun.mall.common.base.BaseActivity
import com.baozhun.mall.common.ext.showToast
import com.baozhun.mall.common.model.bean.ExpressInfoBean
import com.baozhun.mall.common.util.Constants
import com.baozun.houji.order.R
import com.baozun.houji.order.adapter.LogisticInfoAdapter
import com.baozun.houji.order.databinding.ActivityLogisticsDetailBinding
import com.baozun.houji.order.viewmodel.LogisticsDetailViewModel
import com.blankj.utilcode.util.IntentUtils
import com.jaeger.library.StatusBarUtil
import me.hgj.jetpackmvvm.ext.util.copyToClipboard


/**
 * @Title：物流详情页面
 * @Description：
 * @Author：xing.luo
 * @Since：2022/11/20
 * @Version：1.0.0
 */
class LogisticsDetailActivity : BaseActivity<LogisticsDetailViewModel, ActivityLogisticsDetailBinding>() {

    private val expressInfoList by lazy { intent.getSerializableExtra(Constants.Order.LOGISTICS_INFO) as ArrayList<ExpressInfoBean>? }
    private val isSingleLogistics by lazy { intent.getSerializableExtra(Constants.Order.IS_SINGLE_LOGISTICS) as Boolean? }
    private val logisticInfoAdapter by lazy { LogisticInfoAdapter(arrayListOf()) }

    companion object {
        /**
         * 由[isSingleLogistics]来控制是否显示recycleview，订单详情过来不显示列表
         */
        fun start(context: Context, expressInfoList: ArrayList<ExpressInfoBean?>, isSingleLogistics: Boolean = true) {
            var intent = Intent(context, LogisticsDetailActivity::class.java)
            intent.putExtra(Constants.Order.LOGISTICS_INFO, expressInfoList)
            intent.putExtra(Constants.Order.IS_SINGLE_LOGISTICS, isSingleLogistics)
            context.startActivity(intent)
        }
    }

    override fun initView(savedInstanceState: Bundle?) {
        StatusBarUtil.setTransparentForImageView(this, mDataBinding.titleBar)
        mViewModel.isSingleLogistics.value = isSingleLogistics
        if (isSingleLogistics == true && expressInfoList?.isNotEmpty() == true) {
            mViewModel.currentExpressInfo.value = expressInfoList?.get(0)
            //物流信息recycleView
            mDataBinding.rvLogisticsInfo.adapter = logisticInfoAdapter
            logisticInfoAdapter.setList(expressInfoList?.get(0)?.express_detail)
        }

    }

    override fun onClick(v: View?) {
        super.onClick(v)
        when (v?.id) {
            R.id.tv_copy -> {
                copyToClipboard(mViewModel.currentExpressInfo?.value?.express_no)
                showToast(com.baozhun.mall.res.R.string.alr_copy)
            }
            R.id.tv_call_phone -> {
                startActivity(IntentUtils.getDialIntent(mViewModel.currentExpressInfo?.value?.express_phone.toString()))
            }
        }
    }
}